<?php 

if (isset($attemptDetails) && $attemptDetails)

{

	//$user=Users::model()->getModel('USER-ID', array('userid'=>$attemptDetails->user_id));

	$quizdetails=Quiz::model()->getModel('QUIZ-ID', array('quizid'=>$attemptDetails->quiz_id));	

	//$chapterdetails=Chapter::model()->getModel('CHAPTER-ID',  array('chapterid'=>$attemptDetails->chapter_id));

	$userattemptdetails=UserQuizAttemptDetails::getList("ATTEMPT-ID",array('attemptid'=>$attemptDetails->id));

	$usercorrectattempts=UserQuizAttemptDetails::getList("ANSWER-STATUS",array('attemptid'=>$attemptDetails->id,'status'=>'correct'));

	

	$questiontotal=Quiz::getQuestionTotalPoints($attemptDetails->quiz_id,$attemptDetails->id);

	$percentageGained=($attemptDetails->total_points/$questiontotal)*100;

}



?>



<div class="bodywrap"> 

   

   <div data-role="page" id="page1" data-theme="e" class="searchPage" data-url="page=page1"> 

    <div data-role="content" style="margin:0;padding:0">

        

            <ul data-role="listview" data-inset="true" data-theme="e" style="margin:0;padding:0">

                <li id="listitem" style="margin:0;padding:0; border:0">

                        <div class="subhead"><?php echo $quizdetails->title." Quiz Result"; ?></div>

  <div id="numberlist" style="position:relative; top: 7px; padding:1%; color:#fff; text-shadow: 0 1px 1px #000; text-align:center; width:78%; margin:0 auto; background:#233f8c; border-radius: 8px;
	-webkit-border-radius: 8px; 
	-moz-border-radius: 8px;">

    <h4><b style="font-weight:bold; color:black"></b><span style="color:#fff"> <?php 

	if($attemptDetails->result=="fail")

	{

		echo " Sorry....You lost the Game(You need to get atleast <span style='color:green; font-weight:bold'>".$quizdetails->passing_percentage."%"."</span> to pass) <br/> Please try again later.";

	}

	else

	echo "Congratulations!!!! You Won the quiz.  ".$attemptDetails->total_points." points Rewarded to your account";

?></span><br/>

    </h4>

  </div>

  <?php 	if($attemptDetails->result=="pass"){?>                      

	<div class="quizimg" align="center"><img src="<?php echo Yii::app()->request->baseUrl; ?>/images/congratulations.jpg" height="10%" width="20%"/></div>
	<?php $nextlevel=$level+1;
	$nooflevel=Quiz::model()->find('id=?',array($attemptDetails->quiz_id)); 
  $limit = $nooflevel->no_of_questions; $flag = "false";
	if($nooflevel->no_of_level>$level)
	{
  $quiz=Questions::getList('QUIZ-ID-RAND-LIMIT',array('quizid'=>$nooflevel->id,'level'=>$nextlevel,'limit'=>$limit));  

if(count($quiz)==$limit)
{
$flag="true";  
?>
	<div class="quizbutton"><a data-icon="arrow-r" rel="external" href="<?php echo ApplicationConfig::getURL('', 'site', 'playQuiz',array('quizid'=>$attemptDetails->quiz_id,'level'=>$nextlevel))?>"  data-role="button" class="ui-btn-right" data-theme="e" ><?php echo "Next Level";?></a></div>
   <?php } 
   
   if($flag=="false")
echo "No Levels under this quiz/ Levels doesn't have sufficient Questions"; 
   
   
   }
   
   
   
   }else{?>

  	<div class="quizimg" align="center"><img src="<?php echo Yii::app()->request->baseUrl; ?>/images/TryAgain.gif" height="10%" width="20%"/></div> 
    <div class="quizbutton"><a data-icon="arrow-r" rel="external" href="<?php echo ApplicationConfig::getURL('', 'site', 'playQuiz',array('quizid'=>$attemptDetails->quiz_id,'level'=>$level))?>"  data-role="button" class="ui-btn-right" data-theme="e" ><?php echo "Play Again";?></a></div>

   <?php }?>	 

	<div class="quizbutton"><a data-icon="arrow-r" rel="external" href="<?php echo ApplicationConfig::getURL('', 'site', 'postQuizDetails',array('attemptid'=>$attemptDetails->id,'message'=>$message,'level'=>$level))?>"  data-role="button" class="ui-btn-right" data-theme="e" ><?php echo "View Quiz Summary";?></a></div>

      <br clear="all"/> 





			         	</li>

            </ul>

       

    </div>

</div>



</div>    

